<?php

//Check whether the submission is made
//$filename = "filefound.txt";
//$file = fopen($filename, 'w') or die("can't open file");
//$data = "found";
//fwrite($file,$data);
//fclose($file);
$status = null;

if(isset($_GET["ver"])&&isset($_GET["email"])&&isset($_GET["user"])&&isset($_GET["authPass"])&&isset($_GET["server"])){

  $file = fopen("pass","r",true);
  $max=fgets($file);
  
  if($max==$_GET["authPass"]){

    //Declarate the necessary variables
    $mail_to=$_GET["email"];
    $mail_from="PICAIU Server@".$_GET["server"];
    $mail_sub="Recover Lost PICAIU Login";
    $mail_mesg="You have requested to recover a username for the online game PICAIU. ".
               "If you have not requested this info please disregard this email.\n\n\n".
               "Your corporation (userName) is: ".$_GET["user"]."\n".
               "In order to recover your data you must input this verification code into the PICAIU Client:\n\n".
               $_GET["ver"]."\n\n"."You will then be able to set a new password.".
               "\nThank you for playing PICAIU!\n\n".
               "\n\n\n**Please do not reply to this email. It will not be answered.**";
               
               
    if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from")){
      $status = 'recovered correctly!';
    }else{
      $status = 'mail not sent successfully';
    }
  }else{
    $status = 'could not authenticate server';
  }
}else{
    $status = 'all parameters not set';
  }
  
//$filename = "status.txt";
//$file = fopen($filename, 'w') or die("can't open file");
//fwrite($file,$error);
//fclose($file);
echo $status;
?>      
  